package cn.imvc.app.controllers.system;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;

import cn.imvc.app.entities.Group;
import cn.imvc.app.models.GroupModel;
import cn.imvc.app.models.RoleGroupModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;

public class RoleGroupControllerImpl implements RoleGroupController {

	public String roles;
	public String groups;
	public int id;
	public int[] groupid;
	public void setId(int id) {
		this.id = id;
	}

	@Autowired
	private RoleGroupModel  roleGroupModel;
	@Autowired
	private GroupModel groupModel;
	public String index() {
		roles=roleGroupModel.getRoles();
		return "role-group/index";
	}

	public String show() {
		groups=roleGroupModel.getGroupTree(id);
		return "role-group/show";
	}

	public String create() {
		Set<Group> groups=new HashSet<Group>();
		if(groupid!=null)
		for (int gid : groupid) {
			groups.add(groupModel.get(gid));
		}
		roleGroupModel.saveRoleGroup(id, groups);
		return Render.json(new DialogBean("200", "保存成功","role-group","closeCurrent"));
	}

}
